/**
 * 
 */
package com.springvision.yuanfeng.device.facade.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.springvision.yuanfeng.device.entity.Device;
import com.springvision.yuanfeng.device.entity.DeviceMessage;
import com.springvision.yuanfeng.device.facade.DeviceFacade;
import com.springvision.yuanfeng.device.mapper.DeviceMapper;
import com.springvision.yuanfeng.device.service.DeviceService;
import com.springvision.yuanfeng.device.service.DeviceStatService;
import com.springvision.yuanfeng.devlocal.entity.DevLocalTmp;
import com.springvision.yuanfeng.devlocal.mapper.DevLocalTmpMapper;
import com.springvision.yuanfeng.devlocal.service.DevLocalTmpService;
import com.springvision.yuanfeng.locale.entity.DevStation;
import com.springvision.yuanfeng.locale.service.DevStationService;

/**
 * @author Administrator
 *
 */
@Service
@Lazy(false)
@Transactional(rollbackFor = Exception.class)
public class DeviceFacadeImpl implements DeviceFacade, Serializable {

	@Autowired
	private DeviceService deviceService;

	@Autowired
	private DevLocalTmpService devLocalTmpService;

	@Autowired
	private DeviceStatService deviceStatService;

	@Autowired
	private DevStationService devStationService;

	@Override
	public Map<String, List<Device>> getDevice(String staId) {
		Map<String, List<Device>> map = new HashedMap();
		// 场站信息，num,位置信息，A,B-name
		DevStation station = devStationService.get(staId);
		// 所有录入的信息
		List<DevLocalTmp> locations = devLocalTmpService.findAll(staId);
		// 所有设备的deviceId,deviceCode,reportValue
		Map<String, DeviceMessage> realMsgs = deviceStatService.getAllDeviceValueNow2(staId, null);
		List<Device> aList = new ArrayList<>();
		List<Device> baseList = new ArrayList<>();
		List<Device> bList = new ArrayList<>();
		if (station.getNums() != null) {
			for (int i = 0; i < station.getNums(); i++) {
				aList.add(new Device(realMsgs.get(locations.get(i).getADev()), station.getaConfig(), i, 100));
				baseList.add(new Device(realMsgs.get(locations.get(i).getBaseDev()), "基坑", i, 1));
				bList.add(new Device(realMsgs.get(locations.get(i).getBDev()), station.getbConfig(), i, 100));
			}
			map.put("A", aList);
			map.put("B", baseList);
			map.put("C", bList);
		}
		return map;
	}

}
